/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;

using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;

using ELE.EnterpriseLibrary.Aspects.Sinks;

namespace ELE.EnterpriseLibrary.Aspects.Properties
{

  /// <summary>
  /// Context-property which is added to the target context by CLR during the 
  /// object activation phase of a context-bound object's lifecycle.
  /// This property also functions as a factory for server context sinks, namely, Aspects.Sinks.ModifiedLoggingServerSink or Aspects.Sinks.LoggingServerSink
  /// </summary>
  public class AspectProperty : IContextProperty, IContributeServerContextSink
  {
    private string mConfigFile;
    /// <summary>
    /// No arg constructor of a property
    /// </summary>
    public AspectProperty() { }
    /// <summary>
    /// Configuration object for aspect properties
    /// </summary>
    /// <param name="configFile"></param>
    public AspectProperty(string configFile)
    {
      mConfigFile = configFile;
    }
    /// <summary>
    /// Impl of the interface property
    /// </summary>
    public string Name { get { return "AspectProperty"; } }
    /// <summary>
    /// Returns true allways, impl of interface
    /// </summary>
    /// <param name="newCtx"></param>
    /// <returns></returns>
    public bool IsNewContextOK(Context newCtx) { return true; }
    /// <summary>
    /// Does nothing on impl of interface
    /// </summary>
    /// <param name="newContext"></param>
    public void Freeze(Context newContext) { }
    /// <summary>
    /// Returns the sink to be called on interception
    /// </summary>
    /// <param name="nextSink"></param>
    /// <returns></returns>
    public IMessageSink GetServerContextSink(IMessageSink nextSink)
    {
      return new AspectServerSink(nextSink, mConfigFile);
    }
  }
}
